package com.xiaoy.core.base.security.user.service;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xiaoy.core.base.security.user.dao.UserDao;
import com.xiaoy.core.base.security.user.dao.UserRoleDao;
import com.xiaoy.core.base.security.user.entity.UserRole;
import com.xiaoy.core.base.util.store.config.ConfigTable;
import com.xiaoy.dao.DaoUtil;

@Service
public class UserRoleService {

	@Resource
	private DaoUtil dao;
	public void userSettingRole (long userId,long...roleIds) throws Exception  {
		
		if (roleIds!=null) {
			for (long rid : roleIds) {
				String sql = "insert into "+ConfigTable.Security.USER_ROLE_TABLENAME +"(id,role_id,user_id)values ("+ConfigTable.getSeq()+",?,?)";
				dao.saveOrUpdate(sql,rid,userId);
			}
		}else {
			throw new Exception("user setting roles ,roleId is not null");
		}
	}
	
	@Transactional
	public void userSettingRoles (long[] userIds,long...roleIds) throws Exception  {
		
		if (userIds!=null) {
			for (long uid : userIds) {
				userSettingRole(uid, roleIds);
			}
		}else {
			throw new Exception("user setting roles ,userIds is not null");
		}
	}
	
	public void roleSettingUser () {
		
	}
	
}


